<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #bt1 {
            width: 100px;
            height: 100px;
            background-color: red;
        }
        #bt2 {
            width: 50px;
            height: 50px;
            background-color: blue;
        }
        #bt3 {
            width: 30px;
            height: 30px;
            background-color: yellow;
        }
    </style>
</head>
<body>
    <div id="bt1">
        <div id="bt2">
            <div id="bt3"></div>
        </div>
    </div>
    <script>
        const bt1 = document.getElementById("bt1");
        const bt2 = document.getElementById("bt2");
        const bt3 = document.getElementById("bt3");
        // 浏览器默认是冒泡
        // bt1.onclick = function(event) {
        //     console.log("1");
        // }
        // bt2.onclick = function(event) {
        //     console.log("2");
        // }
        // bt3.onclick = function(event) {
        //     console.log("3");
        // }
        // onclick DOM0级别事件 attachEvent addEventListener DOM2级别 兼容性 IE9+
        
        // 事件捕获
        // bt3.addEventListener('click',function(event) {
        //     console.log("3");
        // },true) // useCapture 使用捕获
        // bt2.addEventListener('click',function(event) {
        //     console.log("2");
        // },true)
        // bt1.addEventListener('click',function(event) {
        //     console.log("1");
        // },true)

        // 阻止冒泡 两种方法
        bt3.addEventListener('click',function(event) {
            // event.stopPropagation() ||
            if(event.target === event.currentTarget) {
                console.log("3");
            }
        })
        bt2.addEventListener('click',function(event) {
            // event.target 返回 触发事件的元素
            // event.currentTarget 返回 绑定事件的元素
            // event.stopPropagation() ||
            if(event.target === event.currentTarget) {  
                console.log("2");
            }
        })
        bt1.addEventListener('click',function(event) {
            // event.stopPropagation() ||
            if(event.target === event.currentTarget) {
                console.log("1");
            }
        })
    </script>
</body>
</html>